<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
        对象的解构赋值        
         */
        /* const obj = {
            name: 'jack',
            age: 24,
            sex: 'boy'
        }
        let name = obj.name;
        let age = obj.age;
        let sex = obj.sex;
        console.log(name, age, sex); */
        // 属性名变量名一致
        /* const obj = {
            name: 'jack',
            age: 24,
            sex: 'boy'
        } */
        /* let {
            name,
            age,
            sex
        } = obj;
        console.log(name, age, sex); */

        /*  let name = obj.name;
         let age = obj.age;
         let sex = obj.sex;

         let {
             name:name,
             age:age,
             sex:sex
         } = obj */
        /*  let {
            name,
            age,
            sex
        } = obj;
        console.log(name, age, sex);
 */
        // 属性名和变量名不一致时
        /* 
                const obj = {
                    name: 'jack',
                    age: 24,
                    sex: 'boy'
                } */
        // let age = obj.age;
        // let sex1 = obj.sex;
        /* let{
            name:name,
            age:age,
            sex:sex1
        } = obj; */
        /* let {
            name,
            age,
            sex: sex1
        } = obj
        console.log(name, age, sex1); */

        // 默认值
        const obj = {
            name: 'jack',
            age: 24,
            sex: 'boy' //若是有值，则使用改值，若是没有值，则使用默认值
        }
        let {
            name,
            age,
            sex = 'rose shi nv hai', //默认值
            hobby
        } = obj
        console.log(name, age, sex, hobby);

        /* let name 
        let age
        let sex = 'morenzhi'

        let name = obj.name;
        // 新值
        let sex = obj.sex;

        let {
            name:name,
            age:age
            sex:sex
        } */
        /*  let{
                name,
                age,
                sex
            
         }=obj; */
    </script>
</body>
</html>